
json = {}

local url = "http://api.seniverse.com/v3/weather/now.json?key=StzMhbiC18omHf3JH&location=Qingpu&language=zh-Hans&unit=c"
local url2 = "http://api.seniverse.com/v3/weather/now.json?key=Sz5sBFFnbqvCoZMxz&location=Shanghai&language=zh-Hans&unit=c"
json.weather = {}
local mt = {}
local t = {metatable = mt}
mt.__newindex = function(table, key, value)
    if 
    (key == "temperature") or 
    (key == "text") or 
    (key == "humidity") or 
    (key == "wind_speed")
    then
        rawset(json.weather, key, value)
    end
end

function json.decode_weather()
    local humidity, text, temperature, wind_speed
    local decoder = sjson.decoder(t)
    http.get(url, nil, function(code, data)
        if (code < 0) then
          print("HTTP request failed")
          return false
        else
            decoder:write(data)
        end
    end)

    return true
end

return json